<template>
  <div>
    <div class="store-main">
      <div class="account-top-left">
        <el-input v-model="search" style="width: 300px;" placeholder="请输店铺名或店主名">
          <el-button slot="append"  icon="el-icon-search" @click.prevent="getStoreData(1,6)"></el-button>
        </el-input>
      </div>
      <el-table
        :data="pageStoreData.records"
        style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="店铺名称">
                <span>{{ props.row.storename }}</span>
              </el-form-item>
              <el-form-item label="店主">
                <span>{{ props.row.linkman }}</span>
              </el-form-item>

              <el-form-item label="联系电话">
                <span>{{ props.row.phone }}</span>
              </el-form-item>

              <el-form-item label="店铺地址">
                <span>{{ props.row.address }}</span>
              </el-form-item>
              <el-form-item label="餐饮许可证">
                <el-image
                  style="width: 100px; height: 100px"
                  :src="props.row.permit"
                  :preview-src-list="[props.row.permit]">
                </el-image>
              </el-form-item>
              <el-form-item label="营业执照">
                <el-image
                  style="width: 100px; height: 100px"
                  :src="props.row.license"
                  :preview-src-list="[props.row.license]">
                </el-image>
              </el-form-item>
              <el-form-item label="创建时间">
                <span>{{ props.row.createdate }}</span>
              </el-form-item>
              <el-form-item label="更新时间">
                <span>{{ props.row.updatedate }}</span>
              </el-form-item>
              <el-form-item label="驳回原因" v-show="props.row.status==2">
                <span>{{ props.row.rejectreason }}</span>
              </el-form-item>



            </el-form>
          </template>
        </el-table-column>
        <el-table-column
          label="ID"
          prop="id">
        </el-table-column>
        <el-table-column
          label="商铺名称"
          prop="storename">
        </el-table-column>
        <el-table-column
          label="店主姓名"
          prop="linkman">
        </el-table-column>
        <el-table-column
          label="联系电话"
          prop="phone">
        </el-table-column>
        <el-table-column
          label="申请人账号"
          prop="createuser">
        </el-table-column>
        <el-table-column
          label="商铺状态"
          prop="storestatus">
          <template slot-scope="scope" >
            <span v-text="scope.row.status==0?'待处理':scope.row.status==1?'已同意':'已驳回'"></span>
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              :disabled="scope.row.status!=0?true:false"
              @click="enableBtn(scope.row.id)"
            >同意</el-button>
            <el-button
              size="mini"
              type="danger"
              :disabled="scope.row.status!=0?true:false"
              @click="openBtn(scope.row.id)"
            >驳回</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageStoreData.current"
        :page-sizes="[6, 8, 10, 12]"
        :page-size="pageStoreData.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageStoreData.total">
      </el-pagination>
    </div>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      @close="handleClose">
        <span>

        <el-input v-model="reason" style="width: 200px" placeholder="请输入原因"></el-input>
        </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="disableBtn">确 定</el-button>
       </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "ApprovalManger",
    data(){
      return {
        registerId:"",
        dialogVisible:false,
        reason:"",
        search:"",
        pageStoreData:{
          total:10,
          current:1,
          size:6,
          records:[
            {
              id:1,
              storename:"胖娃烧烤",
              linkman:"胖娃",
              phone:"13372602740",
              address:"重庆",
              license:"http://localhost/static/img/img-temp06.png",
              permit:"http://localhost/static/img/img-temp06.png",
              status:2,
              createuser:"chao",
              createdate:"2020-12-03",
              updatedate:"2020-12-05",
              rejectReason:""
            },
            {
              id:1,
              storename:"胖娃烧烤",
              linkman:"胖娃",
              phone:"13372602740",
              address:"重庆",
              license:"http://localhost/static/img/img-temp06.png",
              permit:"http://localhost/static/img/img-temp06.png",
              status:1,
              createuser:"chao",
              createdate:"2020-12-03",
              updatedate:"2020-12-05",
              rejectReason:""
            },
            {
              id:1,
              storename:"胖娃烧烤",
              linkman:"胖娃",
              phone:"13372602740",
              address:"重庆",
              license:"http://localhost/static/img/img-temp06.png",
              permit:"http://localhost/static/img/img-temp06.png",
              status:0,
              createuser:"chao",
              createdate:"2020-12-03",
              updatedate:"2020-12-05",
              rejectReason:""
            }
          ]
        }
      }
    },
    methods:{
      handleClose(){
        this.reason="";
      },
      openBtn(id){
        this.dialogVisible=true;
        this.registerId=id;
      },
      disableBtn(){
        this.$http.post("/storeRegister/disableRegister",{
          id:this.registerId,
          reason:this.reason
        }).then(resp=>{
          if(resp.data.code==200) {
            this.dialogVisible=false;
            this.$message({
              showClose: true,
              message: resp.data.message,
              type: 'success'
            });
            this.getStoreData(this.pageStoreData.current,this.pageStoreData.size)
          }
        })
      },
      enableBtn(id){
        this.$http.post("/storeRegister/enableRegister/"+id).then(resp=>{
          if(resp.data.code==200) {
            this.$message({
              showClose: true,
              message: resp.data.message,
              type: 'success'
            });
            this.getStoreData(this.pageStoreData.current,this.pageStoreData.size)
          }
        });
      },
      // disableBtn(id){
      //   this.$http.get("/storeInfo/disableStore/"+id).then(resp=>{
      //     if(resp.data.code==200) {
      //       this.$message({
      //         showClose: true,
      //         message: resp.data.message,
      //         type: 'success'
      //       });
      //     }
      //   });
      // },
      handleSizeChange(val){
        this.getStoreData(this.pageStoreData.current,val);
      },
      handleCurrentChange(val) {
        this.getStoreData(val,this.pageStoreData.size)
      },
      getStoreData(pageNum,pageSize){
        this.$http.get("/storeRegister/getAllByPage",{
          params:{
            pageNum:pageNum,
            pageSize:pageSize,
            search:this.search
          }
        }).then(resp=>{
          this.pageStoreData=resp.data.data;
        })
      }
    },
    created() {
      this.getStoreData(1,6);
    }
  }
</script>

<style scoped>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0px;
    margin-bottom: 0;
    width: 50%;
  }
</style>
